'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:FinanceFWjzCtrl
 * @description
 * # FinanceFWjzCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('FinanceFWjzCtrl', function ($scope,localStorageService, openApi, Util, $location, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
        $scope.chooseinfo = function () {
            var relModuleObj = {
                name: "FinanceFGcspCtrl",
                selectTab: "project_money_select",
                selectTabContent: "工程名称"
            };
            // 清掉关联的编号
            var params = $scope.param;
            Util.savaParamForReview(params, id);
            Util.savaDataforsearch(relModuleObj);
            if ($scope.param.formKey === "Xm_ProjectStore") {
                $location.path("project/chooseproject");
            } else {
                Util.savaDataforsearch(relModuleObj);
                $location.path("finance/choosepeople")

            }
        };
        $scope.projectsource = [
            {
                key: "工程合同",
                value: "Project_ContractApplySingle"
            },
            {
                key: "项目信息",
                value: "Xm_ProjectStore"
            }
        ];
        $scope.submit = function (operationId) {

            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.outRun;
            options.param = angular.copy($scope.param, {});
            FormSubmit.submit(options, $scope);
        };
        $scope.validate = function () {
            if (!$scope.param.projectName) {
                Util.Toast("请选择工程名称");
                return;
            }
            if (!$scope.param.validityDate) {
                Util.Toast("请选择预至有效期");
                return;
            }
            if (!$scope.param.money) {
                if ($scope.param.money !== 0) {
                    Util.Toast("请填写开具金额");
                    return;
                }
            }
            if (!$scope.param.projectAddress) {
                Util.Toast("请填写工程所在地税务部门报验需要的相关资料");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
                var data = localStorageService.get("projectinfo");
                localStorageService.remove("projectinfo");
                $scope.param = Object.assign({}, $scope.param, data);
                $scope.param.formKey = $scope.param.formKey || $scope.projectsource[0].value;
            });
        };
        // 初始化
        init();
    });